﻿using System;
using System.Collections.Generic;
using System.Text;
using Barbar.MapReport.Common.Drawing.Commands;
using Barbar.MapReport.Common;
using Barbar.MapReport.Common.Drawing;
using JsonSharp.Collections;
using System.Drawing;
using JsonSharp.Values;
using Barbar.MapReport.HtmlRender.Json;
using Barbar.MapReport.HtmlRender.Operations.Legends;
using Barbar.MapReport.HtmlRender.Operations.Regions;
using System.Web.UI.HtmlControls;

namespace Barbar.MapReport.HtmlRender.Operations {
  internal class AddRegionsWithBusinessProcessingOperation : RenderBaseOperation, IServerCallbackOperation, ILegendOperation {
    private AddRegionsWithBusinessProcessingCommand m_Command;
    private RegionsWithBusinessProcessingData m_Data;

    public AddRegionsWithBusinessProcessingOperation(AddRegionsWithBusinessProcessingCommand command) {
      m_Command = command;
    }

    private void EnsureData() {
      if (m_Data == null)
        m_Data = new RegionsWithBusinessProcessingData(m_Command);
    }

    #region RenderBaseOperation Members

    protected override void RenderInternal(RenderingContext context) {
    }

    #endregion

    #region IServerCallbackOperation Members

    public DataLocation DataLocation {
      get { return m_Command.DataLocation; }
    }

    public MapCallbackService CallbackService {
      get { return new BusinessRegionCallbackService(); }
    }

    public object Value {
      get {
        EnsureData();
        return m_Data;
      }
    }

    #endregion

    #region ILegendOperation Members

    public HtmlControl RenderLegend() {
      EnsureData();
      LegendHtmlRender renderer = new LegendHtmlRender(m_Data.LegendRangeList, m_Command.LegendDescription);
      return renderer.CreateLegendMarkup();
    }

    #endregion
  }
}
